<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    function foo() {
      console.log("foo function1");
      console.log("foo function2");
      throw new Error("错误信息")
      console.log("foo function3");
      console.log("foo function4");
    }

    function test() {
      // 现在我自己捕获异常，异常就不会逐层传递给(抛给)浏览器，那么后续的代码就可以正常执行
      try {
        foo()
      } catch (error) {
        console.log(error.message, '信息');
        console.log(error.name, '名称');
        console.log(error.stack, '调用栈');
      } finally {
        console.log("这个最后一定会执行的");
      }
      foo()
    }

    function bar() {
      test()
    }

    bar()
    console.log("-----");
  </script>
</body>

</html>